ALTER TABLE dbo.Persona DROP CONSTRAINT UX_Persona;
GO
ALTER TABLE dbo.Persona ADD
    CONSTRAINT UX_Persona  UNIQUE (usuario);


IF EXISTS (SELECT * FROM sysobjects WHERE name = 'SelectCommandPersona' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.SelectCommandPersona
GO

CREATE PROCEDURE dbo.SelectCommandPersona
as
	SET NOCOUNT ON;
SELECT *FROM Persona
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'SelectCommandPersonaByNickName' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.SelectCommandPersonaByNickName 
GO
CREATE PROCEDURE dbo.SelectCommandPersonaByNickName 
(
  @usuario nchar(30)

)
AS
	SET NOCOUNT ON;
SELECT *FROM Persona WHERE  usuario = @usuario
GO

IF EXISTS (SELECT * FROM sysobjects WHERE name = 'InsertCommandPersona' AND user_name(uid) = 'dbo')
	DROP PROCEDURE dbo.InsertCommandPersona
GO

CREATE PROCEDURE dbo.InsertCommandPersona
(
	
	@usuario nchar(30),
	@nombre nchar(30),
	@password nchar(50)
)
AS
DECLARE @ID INT
SET @ID = (SELECT MAX(codigo) FROM [Persona])  
                                                                                                                                                                                                            
IF @ID IS NULL OR @ID=0                                                                                                                                                                                                                           
	SET @ID = 1                                                                                                                                                                                                                                      
ELSE                                                                                                                                                                                                                                                            
 SET @ID = @ID + 1  

	SET NOCOUNT OFF;
INSERT INTO [Persona] ([codigo], [nombre],[usuario],[password]) VALUES (@id, @nombre, @usuario, @password)
GO


--IF EXISTS (SELECT * FROM sysobjects WHERE name = 'UpdateCommandPersona' AND user_name(uid) = 'dbo')
--	DROP PROCEDURE dbo.UpdateCommandPersona
--GO
----
----CREATE PROCEDURE dbo.UpdateCommandPersona
----(
----	@Original_codigo int,
----	@Persona nchar(100),
----	@nombre nchar(100)
----	
----)
----AS
----	SET NOCOUNT OFF;
----UPDATE [Persona] 
----	SET 
----	[Persona] = @Persona, 
----	[nombre] = @nombre
----WHERE ([codigo] = @Original_codigo)
----	
----GO
----
----IF EXISTS (SELECT * FROM sysobjects WHERE name = 'DeleteCommandPersona' AND user_name(uid) = 'dbo')
----	DROP PROCEDURE dbo.DeleteCommandPersona
----GO
----
----CREATE PROCEDURE dbo.DeleteCommandPersona
----(
----	@Original_codigo int
----)
----AS
----	SET NOCOUNT OFF;
----DELETE FROM [Persona] WHERE ([codigo] = @Original_codigo) 
----GO
----
